Optimize shared memory operations#1167
Conversation
5ac906a to
ab50454
Compare
There was a problem hiding this comment.
Pull request overview
This PR optimizes shared memory operations in Hyperlight by implementing chunked aligned memory access using u128 (16-byte) operations, significantly improving performance for memory-heavy operations like snapshot restoration and parameter copying. The optimization is inspired by PostgreSQL's memory handling techniques.
Changes:
- Replaced byte-by-byte memory operations with aligned u128 chunk processing
- Added comprehensive benchmarks for shared memory operations (fill, copy_to_slice, copy_from_slice)
- Implemented three-phase approach: handle unaligned head bytes, process aligned chunks, handle remaining tail bytes
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/hyperlight_host/src/mem/shared_mem.rs | Optimized copy_to_slice, copy_from_slice, and fill methods with aligned u128 chunk operations |
| src/hyperlight_host/benches/benchmarks.rs | Added new benchmark suite for shared memory operations with 1MB and 64MB test sizes |
ab50454 to
b9edfdd
Compare
b9edfdd to
7de43ec
Compare
7de43ec to
0767f2b
Compare
andreiltd
left a comment
There was a problem hiding this comment.
Nice speed up!
My first instinct looking at the patch was that we should be using: https://doc.rust-lang.org/std/primitive.slice.html#method.align_to to divide mem into aligned slices, but then for shared memory we actually need to iterate over raw pointers to use volatile semantics and using slices will make it a bit more annoying. We could still use it for fill method but I see the value in keeping all the functions similar :)
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
Signed-off-by: Ludvig Liljenberg <4257730+ludfjig@users.noreply.github.com>
36c23da to
a4b13f1
Compare
I also thought of using |
Should speed up memory-heavy things in hyperlight such as restoring snapshots, copying memory parameters, etc. u128 proved to be faster than u64.
Inspired by postgres.